package com.yunji.web.base;

import com.yunji.aggregate.model.dto.analysis.*;
import com.yunji.aggregate.model.dto.stock.StatisticsDataParam;
import com.yunji.aggregate.model.vo.analysis.*;
import com.yunji.aggregate.model.vo.base.*;
import com.yunji.aggregate.model.vo.product.ProductOrderStatisticsVO;
import com.yunji.aggregate.service.AnalysisService;
import com.yunji.aggregate.service.BaseAggregateService;
import com.yunji.aggregate.service.ProductAggregateService;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.web.user
 * @Title: AnalysisController
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-09-02 16:47:55      V1.0        HuaAo       新建类
 */
@Api(tags = "管理端-数据分析")
@RestController
@RequestMapping("/container/analysis")
public class AnalysisController extends BaseController {

    @Resource
    AnalysisService business;

    @Resource
    private BaseAggregateService baseAggregate;

    @Resource
    private ProductAggregateService productAggregate;

    /**
     * @Title todayDate
     * @Desc 获取今日数据
     * @Date 2024-09-02 17:03:06.901
     * @Return ResponseHomeCurrentDate>
     */
    @ApiOperation("获取今日数据")
    @GetMapping("/todayData")
    public Response<HomeCurrentVO> todayData() {
        return ResponseHelper.success(business.todayData());
    }

    /**
     * @Title saleTrend
     * @Desc 销售趋势图
     * @Date 2024-09-03 14:25:18.887
     * @Return ResponseList < SaleTrend>>
     */
    @ApiOperation("销售走势图")
    @GetMapping("/saleTrend")
    public Response<List<SaleTrendVO>> saleTrend(@RequestParam Integer trendType) {
        return ResponseHelper.success(business.saleTrend(trendType));
    }

    /**
     * @param trendType 趋势类型
     * @Title earnTrend
     * @Desc 收益趋势图
     * @Date 2024-09-03 16:55:26.788
     * @Return ResponseList < EarnTrend>>
     */
    @ApiOperation("收益统计图")
    @GetMapping("/earnTrend")
    public Response<Map<String, List<EarnTrendVO>>> earnTrend(@RequestParam Integer trendType) {
        return ResponseHelper.success(business.earnTrend(trendType));
    }

    /**
     * @param trendType 趋势类型
     * @Title amountRatio
     * @Desc 商品销售占比
     * @Date 2024-09-04 14:20:45.151
     * @Return ResponseList < ProductRatio>>
     */
    @ApiOperation("商品销售占比")
    @GetMapping("/amountRatio")
    public Response<List<ProductRatioVO>> amountRatio(@RequestParam Integer trendType, @RequestParam Integer ratioType) {
        return ResponseHelper.success(business.amountRatio(trendType, ratioType));
    }

    /**
     * @Title awaitHandle
     * @Desc 待处理事项
     * @Date 2024-09-06 09:23:39.909
     * @Return ResponseAwaitHandleData>
     */
    @ApiOperation("待处理事项")
    @GetMapping("/awaitHandle")
    public Response<AwaitHandleVO> awaitHandle() {
        return ResponseHelper.success(business.awaitHandle());
    }

    @ApiOperation("商品概况")
    @GetMapping("/productInfo")
    public Response<ProductInfoVO> productInfo() {
        return ResponseHelper.success(business.productInfo());
    }

    @ApiOperation("销售统计")
    @PostMapping("/salesStats")
    public Response<List<SaleTrendVO>> salesStats(@RequestBody StatisticsDataParam param) {
        return ResponseHelper.success(business.salesStats(param));
    }

    @ApiOperation("收益统计")
    @PostMapping("/earnsStats")
    public Response<List<PlatformEarnVO>> earnsStats(@RequestBody StatisticsDataParam param) {
        return ResponseHelper.success(business.earnsStats(param));
    }

    @ApiOperation("代理销售列表")
    @PostMapping("/agentSalesList")
    public Response<List<AgentSalesVO>> agentSalesList(@RequestBody StatisticsDataParam param) {
        List<AgentSalesVO> list = baseAggregate.agentSalesList(param);
        return ResponseHelper.successWithPage(list);
    }

    @ApiOperation("代理收益列表")
    @PostMapping("/agentEarnsList")
    public Response<List<AgentEarnsVO>> agentEarnsList(@RequestBody StatisticsDataParam param) {
        List<AgentEarnsVO> list = baseAggregate.agentEarnsList(param);
        return ResponseHelper.successWithPage(list);
    }

    @ApiOperation("网点销售列表")
    @PostMapping("/siteSalesList")
    public Response<List<SiteSalesStatisticsVO>> siteSalesList(@RequestBody StatisticsDataParam param) {
        List<SiteSalesStatisticsVO> list = baseAggregate.siteSalesList(param);
        return ResponseHelper.successWithPage(list);
    }

    @ApiOperation("网点收益列表")
    @PostMapping("/siteEarnsList")
    public Response<List<SiteEarnsStatisticsVO>> siteEarnsList(@RequestBody StatisticsDataParam param) {
        List<SiteEarnsStatisticsVO> list = baseAggregate.siteEarnsList(param);
        return ResponseHelper.successWithPage(list);
    }


    @ApiOperation("商品销售统计")
    @PostMapping("/productSalesStats")
    public Response<List<ProductOrderStatisticsVO>> productSalesStats(@RequestBody ProductOrderStatisticsParam param) {
        List<ProductOrderStatisticsVO> list = productAggregate.productSalesStats(param);
        return ResponseHelper.successWithPage(list);
    }

    @ApiOperation("点位销售统计列表")
    @PostMapping("/locationSalesStats")
    public Response<List<LocationSalesStatsVO>> locationSalesStats(@RequestBody LocationSalesStatsParam param){
        return ResponseHelper.successWithPage(baseAggregate.locationSalesStats(param));
    }

    @ApiOperation("点位销售统计图")
    @PostMapping("/locationSalesChart")
    public Response<List<LocationSalesChartVO>> locationSalesChart(@RequestBody LocationSalesStatsParam param){
        param.setExport(true);
        return ResponseHelper.successWithPage(baseAggregate.locationSalesChart(param));
    }

    @ApiOperation("货柜销售统计列表")
    @PostMapping("/containerSalesStats")
    public Response<List<ContainerSalesStatsVO>> containerSalesStats(@RequestBody ContainerSalesStatsParam param){
        return ResponseHelper.successWithPage(baseAggregate.containerSalesStats(param));
    }

    @ApiOperation("货柜销售统计图")
    @PostMapping("/containerSalesChart")
    public Response<List<ContainerSalesChartVO>> containerSalesChart(@RequestBody ContainerSalesStatsParam param){
        param.setExport(true);
        return ResponseHelper.successWithPage(baseAggregate.containerSalesChart(param));
    }

    @ApiOperation("员工数据统计")
    @PostMapping("/staffDataStats")
    public Response<List<StaffDataStatsVO>> staffDataStats(@RequestBody StaffDataStatsParam param) {
        return ResponseHelper.successWithPage(baseAggregate.staffDataStats(param));
    }


    /*--------------------------------------------联动查询--------------------------------------------------*/
    @ApiOperation("统计代理商联动查询")
    @PostMapping("/agentLinkageQuery")
    public Response<List<LinkageQueryVO>> agentLinkageQuery(@RequestBody LinkageQueryParam param) {
        param.setExport(Boolean.TRUE);
        return ResponseHelper.success(business.agentLinkageQuery(param));
    }

    @ApiOperation("统计网点联动查询")
    @PostMapping("/siteLinkageQuery")
    public Response<List<LinkageQueryVO>> siteLinkageQuery(@RequestBody LinkageQueryParam param) {
        param.setExport(Boolean.TRUE);
        return ResponseHelper.success(business.siteLinkageQuery(param));
    }

    @ApiOperation("统计货柜联动查询")
    @PostMapping("/containerLinkageQuery")
    public Response<List<LinkageQueryVO>> containerLinkageQuery(@RequestBody LinkageQueryParam param) {
        param.setExport(Boolean.TRUE);
        return ResponseHelper.success(baseAggregate.containerLinkageQuery(param));
    }

    @ApiOperation("统计商品联动查询")
    @PostMapping("/productLinkageQuery")
    public Response<List<LinkageQueryVO>> productLinkageQuery(@RequestBody LinkageQueryParam param) {
        param.setExport(Boolean.TRUE);
        return ResponseHelper.success(productAggregate.productLinkageQuery(param));
    }

    @ApiOperation("扫描用户统计")
    @PostMapping("/scanStatisticsPage")
    public Response<List<ScanStatisticsVO>> scanStatisticsPage(@RequestBody ScanStatisticsParam param) {
        return ResponseHelper.successWithPage(business.scanStatisticsPage(param));
    }

    @ApiOperation("扫描用户统计(导出)")
    @PostMapping("/scanStatisticsExport")
    public void scanStatisticsExport(@RequestBody ScanStatisticsParam param) {
        param.setExport(true);
        List<ScanStatisticsVO> voList = business.scanStatisticsPage(param);
        ExcelUtil<ScanStatisticsVO> util = new ExcelUtil<>(ScanStatisticsVO.class);
        util.exportExcel(response, voList, "扫码用户统计");
    }

    @ApiOperation("扫描用户统计柱状图")
    @PostMapping("/scanStatisticsGroup")
    public Response<List<ScanStatisticsGroupVO>> scanStatisticsGroup(@RequestBody ScanStatisticsParam param) {
        param.setExport(true);
        return ResponseHelper.success(business.scanStatisticsGroup(param));
    }
}